package servlet.admin.message;

import service.MessageService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet( name = "AdminMessageUpdateServlet")
public class AdminMessageUpdateServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Integer status=Integer.parseInt(request.getParameter("status"));
        Integer newStatus=Integer.parseInt(request.getParameter("newStatus"));
        Integer messageId=Integer.parseInt(request.getParameter("messageId"));
        MessageService service=new MessageService();
        service.updateStatus(messageId,newStatus);

        request.setAttribute("status",status);
        request.getServletContext().getRequestDispatcher("/admin/AdminAllMessageServlet").forward(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
